Returns a data frame describing every model run that fit_models
would execute, without actually fitting any models. Useful for verifying
model specifications and confirming the set of runs before committing to a
potentially long parallel execution.
Arguments
- models
A named list of
model_specobjects, one per model to run. Names become the keys in the returned results list.- data
A data frame, or a named list of data frames. When a list is provided, every model is run once per dataset.
- defs
A named list of definition lists. Each element must contain:
dvCharacter. The dependent variable name.
funFunction (or named list of functions) with signature
f(formula, data, weights), or a character string naming a function (e.g."lm"or"fixest::feols"). A string is wrapped intofunction(f, d, w, ...) <fun>(f, data = d, weights = w, ...), The formula is passed as the first argument, whatever that argument is called. Arguments set withset_argsare passed as further named arguments, so a function fitting such a model needs...or arguments of those names.
and may optionally contain:
extra_termsCharacter vector of terms appended to every model's main terms (but not to its parts; see
set_parts) for this DV only.additional_modelsNamed list of
model_specobjects added to the model set for this DV only.model_modsNamed list of functions of the form
function(model_spec) -> model_spec. Each entry modifies the named base model for this DV only, leaving other DVs unchanged.
- weight_var
Character. Name of a column in
datato use as regression weights. When supplied, each model is run twice: once unweighted and once weighted. DefaultNULL(no weights).- weighted_only
Logical. When
TRUEandweight_varis supplied, only the weighted variants are run. DefaultFALSE.
Value
A tibble with one row per model run and
columns:
defThe name of the definition in
defsthat produced this run (i.e. the key used to index the outer results list returned byfit_models).dvDependent variable name.
modelModel name (from
models).datasetDataset name. Only present when
datais a named list of data frames; omitted for a single data frame.weightedLogical;
TRUEfor weighted runs,FALSEfor unweighted runs. Only present whenweight_varis supplied andweighted_only = FALSE(i.e. when both variants appear); omitted otherwise.keyThe name the corresponding result will have in the inner list for this definition, formed by joining
model,dataset, and weight suffix with".".formulaCharacter representation of the formula that would be passed to the regression function.
argsExtra arguments the model's spec carries (see
set_args), as a one-line summary. Only present when at least one run has them;NAfor runs without arguments.
Examples
base_m <- model_spec(cyl, disp)
models <- list(base = base_m, ext = base_m |> add_terms(hp))
defs <- list(mpg = list(dv = "mpg", fun = "lm"))
preview_fit(models, mtcars, defs)
#> # A tibble: 2 × 5
#> def dv model key formula
#> <chr> <chr> <chr> <chr> <chr>
#> 1 mpg mpg base base mpg ~ cyl + disp
#> 2 mpg mpg ext ext mpg ~ cyl + disp + hp